from django.shortcuts import render
from django.urls import reverse
from django.http import HttpResponse,HttpResponseRedirect
import re

class LoginCheck:


    def __init__(self, get_response):
        self.get_response = get_response
        # 一次性配置和初始化。

    def __call__(self, request):


        # 后台登录页面的校验

        # 前台登录页面校验
        passpath = ['/uc/','/cart/']

        if re.match('/uc/',request.path) or request.path in passpath:
            if not request.session.get('vipuser'):
                return HttpResponseRedirect(reverse('login'))




        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response


























